<?php

namespace App\Http\Controllers\admin;

use Illuminate\Routing\Controller as BaseController;
use Illuminate\Http\Request;
use App\Http\Model\User;

class LoginController extends BaseController
{

    // 登录首页
    public function index(Request $request)
    {   
        return view('admin.login');
    }

    // 用户登录认证
    public function verify(Request $request){
        $username = $request->input('username');
        $password = $request->input('password');

        $res = User::select('password','id')->where('username',$username)->first();
        if (empty($res)) {
            return response()->json(['res'=>false,'msg'=>'用户不存在']);
        }

        if ($res['password'] != md5($password)) {
            return response()->json(['res'=>false,'msg'=>'密码错误']);
        }

        session(['userid'=>$res['id']]);
        return response()->json(['res'=>true,'url'=>action('admin\HomeController@index')]);
    }
}
